
/**
 * 系统配置中的合同管理
 * Created by Administrator on 2018/4/28.
 */

define(function (require,exports,module) {
    var sTpl = require("./contractManage.html");
    require("./contractManage.css");

    var VueComponent = Vue.extend({
        template: sTpl
        ,methods:{
            findAllContractManage:function() {
                var $this = this;
                axios.get(basepath+"/api/sysSetting/findContractManage"
                ).then(function (response) {
                    $this.tableData=response.data;
                });
            },

            addContact:function() {
                this.addContractForm={contractNumber:'',
                    contractAgreemen:'',
                    agreementUnit:'',
                    agreementNumber:'',
                    residueDegree:'',
                    startDate:'',
                    endDate:''};
                this.tl='合同添加'
                this.$refs.baseTable.dialogFormVisible = true;
                this.title='添加成功';

            },
            clear:function(){
                this.$refs.baseTable.dialogFormVisible = false;
            },
            saveClick:function () {
                var $this = this;
                this.$refs.addContractForm.validate(function(validate){
                    if(validate){
                        axios.post(basepath+'/api/sysSetting/saveContractManage',$this.addContractForm
                        )
                            .then(function (response) {
                                $this.$notify({
                                    title: $this.title,
                                    message: $this.title
                                });

                                $this.$refs.baseTable.dialogFormVisible = false;
                                $this.checkContract();

                            });
                    }
                });

            },
            editContact:function (scope) {
                this.tl="合同修改"
                this.$refs.baseTable.dialogFormVisible = true;
                   this.addContractForm=JSON.parse(JSON.stringify(scope.row));
                   this.title='修改成功';
            },
            checkContract:function () {

                var $this = this;
                axios.get(basepath+"/api/sysSetting/checkContractManage",{
                    params: {
                    contractNumber:$this.checkFormInline.contractNumber,
                    contractAgreemen:$this.checkFormInline.contractAgreemen
                    }}
                ).then(function (response) {
                    console.log(response);
                    $this.tableData=response.data;
                });
            },
            delectContact:function(scope){
                    var $this = this ;
                    this.$confirm('确定删除？', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'success'
                    }).then(function() {
                        axios.post(basepath+'/api/sysSetting/delectContractManage',scope.row)
                            .then(function (response) {
                                $this.$notify({
                                    title: '已删除',
                                    message: '已删除'
                                });

                                $this.checkContract();
                            });
                    })

            }
        },
        mounted:function() {

        }
        ,data:function(){
            return {
                tl:'',
                title:'',
                dialogFormVisible: false,
                checkFormInline: {
                    contractNumber:'',
                    contractAgreemen:''
                },
                addContractForm: {
                    contractNumber:'',
                    contractAgreemen:'',
                    agreementUnit:'',
                    agreementNumber:'',
                    residueDegree:'',
                    startDate:'',
                    endDate:''
                },
                scope:{

                }
                ,
                pickerOptions1: {
                    shortcuts: [{
                        text: '今天',
                        onClick:function(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '昨天',
                        onClick:function(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周前',
                        onClick:function (picker) {
                            const date = new Date();
                            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                tableData: {}
            }
        },
        created:function (){
            this.findAllContractManage();
        },
        activated:function () {
            messages.$emit('change','合同配置');
        }

    });
    module.exports = VueComponent;
})
